<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="cn.ac.cintcm.dataconverge.dataAnalyze.form.*,cn.ac.cintcm.dataconverge.researcher.domain.*,
java.util.Map.Entry,com.hs.core.page.PageUtil,com.hs.core.utils.StringUtilTool,cn.ac.cintcm.dataconverge.util.Constants" %>
<%@ page import="org.jfree.chart.ChartFactory,
org.jfree.chart.JFreeChart,
org.jfree.chart.labels.StandardCategoryItemLabelGenerator,
org.jfree.chart.plot.CategoryPlot,
org.jfree.chart.plot.PlotOrientation,
org.jfree.chart.renderer.category.BarRenderer3D,
org.jfree.chart.servlet.ServletUtilities,
org.jfree.data.category.DefaultCategoryDataset,java.awt.Font" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
List tagList = (List)request.getAttribute("tagList");
int tagSize = tagList.size();
Map orgMap = (Map)request.getAttribute("orgMap");
int orgSize = orgMap.size(); 
int allNum = 0;
Double allFund = 0d;
List allOrg = (List)request.getAttribute("allOrg");
List tags = (List)request.getAttribute("topTags");

String subjectYear = (String)request.getAttribute("subjectYear");
String orgid = (String)request.getAttribute("orgId");
String orgRole = (String)request.getAttribute("orgRole");
String state = (String)request.getAttribute("state");
String subjectTag = (String)request.getAttribute("subjectTag");
DefaultCategoryDataset dataset1=new DefaultCategoryDataset ();	
DefaultCategoryDataset dataset2=new DefaultCategoryDataset ();	
DefaultCategoryDataset dataset3=new DefaultCategoryDataset ();	
DefaultCategoryDataset dataset4=new DefaultCategoryDataset ();	
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns:tvns>
<head>
   <link href="<%=basePath%>index/Themes/com/style.css" rel="stylesheet" type="text/css" />
    <script src="<%=basePath%>index/Scripts/Script.js" language="javascript" type="text/javascript"></script>
     <script src="<%=basePath%>js/common.js" language="javascript" type="text/javascript"></script>
<script language="javascript" type="text/javascript" src="<%=path %>/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
function statSubject(){ 
  var content = document.getElementsByName("subjectTag");
  var flag = false;
  for(var i=0;i<content.length;i++){
  	if(content[i].checked){
  		flag = true;
  		break;
  	}
  }
  if(!flag)
     alert("请选择一项统计内容进行统计");
     else
  searchform.action="<%=path%>/subjectAnalyze.htm?action=statByContent";
  searchform.submit(); 
}
function statByTag(tagId){ 
  searchform.action="<%=path%>/subjectAnalyze.htm?action=statByContent&tagId="+tagId;
  searchform.submit(); 
}


</script>
</head>
<body scroll="yes">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
            <td>
               <form name="searchform" action = "<%=path%>/subjectAnalyze.htm?action=statByContent" method="post">
    <div class="r_rtm_tb_mg1">
        <div class="r_rtm_tb1">
            <span>
                <img src="<%=path%>/index/Themes/com/idt_tb_pass.gif" />&nbsp;&nbsp;课题内容统计</span>
        </div>
    </div>  
     <table cellspacing="2" cellpadding="0" width="100%" class="idt_item_mg" id="Table2">
        <tr>
            <td class="fim_l" width="10%">
                统计内容：</td>
            <td class="fim_r"  width="40%">
                <%
                  for(int k = 0;k<tags.size();k++){
                	  Map tag = (Map)tags.get(k);
                	  out.print("<input type=radio name=subjectTag value=\"");
                	  out.print(tag.get("ID")+"\"");
                	 
                	  if((tag.get("ID")+"").equals(subjectTag))
                		  out.print(" checked");
                	  out.print("/>&nbsp;");
                	  out.print(tag.get("NAME"));
                	  out.print("&nbsp;");
                  }
                %>
                
                </td>
            <td class="fim_l" width="10%">
               单位</td>
            <td class="fim_r" nowrap  colspan="2">
                <select name="orgId">
                  <option value="0">-----请选择统计单位-----</option>
                  <%if(allOrg != null && allOrg.size()>0){
                	   for(int m = 0;m<allOrg.size();m++){
                		   Organization org = (Organization)allOrg.get(m);
                		   out.print("<option value=" + org.getId());
                		   if((org.getId()+"").equals(orgid))
                			   out.print( " selected");
                		   out.print(">");
                		   out.print(org.getName());
                		   out.print("</option>");
                	   }
                	  
                  }  %> 
                </select> &nbsp;
                <select name="orgRole">
		    		<option value="0">---请选择单位角色---</option>
		      		<option value="<%=Constants.org_role_leader %>" <%if(Constants.org_role_leader.equals(orgRole)){out.print(" selected");} %>>牵头单位</option>
		      		<option value="<%=Constants.org_role_participant %>" <%if(Constants.org_role_participant.equals(orgRole)){out.print(" selected");} %>>参与单位</option>
		    	</select>
            </td> 
        </tr>
        <tr>
            <td class="fim_l">
                课题状态：</td>
            <td class="fim_r">
                <select name="state" >
		  			<option value="-1" >---请选择课题状态---</option>
					<option value="0" <%if("0".equals(state)){out.print(" selected");} %>>申报中</option>
					<option value="5" <%if("5".equals(state)){out.print(" selected");} %>>未中标</option>
					<option value="1" <%if("1".equals(state)){out.print(" selected");} %>>中标</option>
					<option value="2" <%if("2".equals(state)){out.print(" selected");} %>>在研</option>
					<option value="3" <%if("3".equals(state)){out.print(" selected");} %>>申请结题</option>
					<option value="4" <%if("4".equals(state)){out.print(" selected");} %>>已结题</option>	
				</select>
            </td>
            <td class="fim_l">
                所属年份</td>
            <td class="fim_r" nowrap width="30%"> 
            	<input type="text" class="Wdate" id="subjectYear" value="<%=subjectYear==null?"":subjectYear %>" style="width:40%" name="subjectYear"  onFocus="WdatePicker({el:'subjectYear',dateFmt:'yyyy'})" />
            </td> 
            <td class="fim_r" align="center"  >
                <input type="button" value="统计"  onclick="statSubject()" class="com_btn2" id="Button5">
            </td>
        </tr>
        
    </table> 
            </td>
        </tr>
        </form>
        <tr>
            <td>
                <table border="0" cellpadding="0" cellspacing="0" width="100%">
                    <tr>
                        <td class="main_content_l2">
                            &nbsp;
                        </td>
                        <td>
                            <table border="0" cellpadding="1" cellspacing="2" width="100%">
                                <tr style="background-color: #ACDBEB; height: 30px;">
                                    <th>
                                        序号
                                    </th>
                                    <th>
                                        单位名称
                                    </th>
                                    <%
                                    for(int i = 0;i<tagSize;i++){
                                    	TagStatObj tag = (TagStatObj)tagList.get(i);
                                    	if(tag.isHasSub())
                                    		 out.print("<th><a href=javaScript:statByTag('"+tag.getTagId()+"');>"+tag.getTagName()+"</a></th>"); 
                                    	else
                                        out.print("<th>"+tag.getTagName()+"</th>"); 
                                    } 
                                     %>
                                    <th>
                                            <font color=red>课题总数</font>
                                    </th>
                                    <th>
                                           <font color=red> 中标经费</font>
                                    </th>
                                </tr>
                                <% 
                                   int  index = 0;
                                   Set orgSet = orgMap.entrySet();
                                   Iterator iter = orgSet.iterator();
                                   while(iter.hasNext()){
                                        index++;
                                        Entry entry = (Entry)iter.next();
                                        UnitStatObj org = (UnitStatObj)entry.getValue();
                                        dataset1.addValue(org.getUnitCount(),org.getOrgName(),"");
                                        dataset2.addValue(org.getUnitFund(),org.getOrgName(),"");
                                   		int  flag = index%2;
                                 %>
                                <tr style="height: 23px; <%if(flag == 0){ %>background-color: #fff;"<%}else{ %>background-color:#D3EDFA;"<%} %>>
                                    <td align="center">
                                        <%=index %>
                                    </td>
                                    <td align="center">
                                        <%=org.getOrgName()%>
                                    </td>
                                     <% for(int i = 0;i<tagSize;i++){
                                    	 TagStatObj tag = (TagStatObj)tagList.get(i); 
                                     	 String tagId = tag.getTagId()+""; 
                                     	 out.print("<td align=\"center\">");
                                     	 Integer obj = (Integer)org.getSubjectMap().get(tagId + "#" + org.getOrgId());
                                     	 out.print(obj == null?"0":obj);
                                     		 out.print("</td>");  
                                     }%>
                                     <td align="center">
                                        <%=org.getUnitCount() %>
                                    </td>
                                    <td align="center">
                                        <%=org.getUnitFund()%>
                                    </td>
                                </tr>  
                                 <%} %>
                                 <tr style="height: 23px; background-color: #blue;">
                                     
                                     <td colspan=2 align="center"> 
                                    <font color=red>课题总数</font>
                                    </td>
                                    <%
                                    for(int i = 0;i<tagSize;i++){
                                    	TagStatObj tag = (TagStatObj)tagList.get(i); 
                                        out.print("<th>"+tag.getAllCount()+"</th>"); 
                                        dataset3.addValue(tag.getAllCount(),tag.getTagName(),"");
                                    } 
                                     %>
                                    <td> 
                                    </td>
                                    <td>
                                            
                                    </td>
                                </tr>
                                <tr style="height: 23px; background-color: #red;">
                                     
                                    <td colspan=2 align="center"> 
                                    <font color=red>中标经费</font>
                                    </td>
                                    <%
                                    for(int i = 0;i<tagSize;i++){
                                    	TagStatObj tag = (TagStatObj)tagList.get(i); 
                                        out.print("<th>"+tag.getAllFund()+"</th>"); 
                                        dataset4.addValue(tag.getAllFund(),tag.getTagName(),"");
                                    } 
                                     %>
                                    <td>
                                             
                                    </td>
                                    <td>
                                            
                                    </td>
                                </tr>
                                 <!--  <tr style="height: 23px; background-color: #ffffff;">
                                    <td colspan="<%=tagSize+4%>">
                                        <table border="0" cellpadding="0" cellspacing="0" width="100%">
                                            <tr style="font-weight: bold;">
                                                <td>
                                                    合计：
                                                </td>
                                                <td>
                                                    课题总数：<%=allNum %>
                                                </td>
                                                <td>
                                                    经费：60
                                                </td> 
                                            </tr>
                                        </table>
                                    </td>
                                </tr>  -->
                            </table>
                        </td>
                        <td class="main_content_r2">
                            &nbsp;
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        
    </table>
    <%
    	 
	//JFreeChart chart=ChartFactory.createPieChart3D("",dataset,true,false,false);
	  JFreeChart chart1 = ChartFactory.createBarChart3D("单位课题数目分布",
			"",
			"课题数",dataset1,
			PlotOrientation.VERTICAL,
			true,
			false,
			false);
	
	  	CategoryPlot plot=(CategoryPlot)chart1.getPlot();
	  	BarRenderer3D   renderer   =   new   BarRenderer3D(); 
	    renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
	    renderer.setItemLabelFont(new Font("黑体",Font.PLAIN,12));
	    renderer.setItemLabelsVisible(true);			  
	    //renderer.setLegendItemLabelGenerator(new StandardCategorySeriesLabelGenerator("{0}"));
	    plot.setRenderer(renderer);
	    
	    JFreeChart chart2 = ChartFactory.createBarChart3D("单位课题经费分布",
				"",
				"经费金额",dataset2,
				PlotOrientation.VERTICAL,
				true,
				false,
				false);
		
		  	CategoryPlot plot2=(CategoryPlot)chart2.getPlot();
		  	BarRenderer3D   renderer2   =   new   BarRenderer3D(); 
		    renderer2.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
		    renderer2.setItemLabelFont(new Font("黑体",Font.PLAIN,12));
		    renderer2.setItemLabelsVisible(true);			  
		    //renderer.setLegendItemLabelGenerator(new StandardCategorySeriesLabelGenerator("{0}"));
		    plot2.setRenderer(renderer2);
		    
		    JFreeChart chart3 = ChartFactory.createBarChart3D("课题分类数目分布",
					"",
					"课题数量",dataset3,
					PlotOrientation.VERTICAL,
					true,
					false,
					false);
			
			  	CategoryPlot plot3=(CategoryPlot)chart3.getPlot();
			  	BarRenderer3D   renderer3   =   new   BarRenderer3D(); 
			    renderer3.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
			    renderer3.setItemLabelFont(new Font("黑体",Font.PLAIN,12));
			    renderer3.setItemLabelsVisible(true);			  
			    //renderer.setLegendItemLabelGenerator(new StandardCategorySeriesLabelGenerator("{0}"));
			    plot3.setRenderer(renderer3);
			    JFreeChart chart4 = ChartFactory.createBarChart3D("课题分类经费分布",
						"",
						"经费金额",dataset4,
						PlotOrientation.VERTICAL,
						true,
						false,
						false);
				
				  	CategoryPlot plot4=(CategoryPlot)chart4.getPlot();
				  	BarRenderer3D   renderer4   =   new   BarRenderer3D(); 
				    renderer4.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
				    renderer4.setItemLabelFont(new Font("黑体",Font.PLAIN,12));
				    renderer4.setItemLabelsVisible(true);			  
				    //renderer.setLegendItemLabelGenerator(new StandardCategorySeriesLabelGenerator("{0}"));
				    plot4.setRenderer(renderer4);
	    
	    
	    
		String filename = ServletUtilities.saveChartAsPNG(chart1,500,300,null,request.getSession());
		String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;
		request.getSession().setAttribute("graphURL", graphURL);
		request.getSession().setAttribute("filename", filename);	
	
    
    
    %>
    <table cellspacing="0" cellpadding="0" width="100%" class="idt_bottom_mg" border="0">
          <tr>
              <td align="center"> 
              <img src="<%=graphURL%>" style="width:99%"></img>
              </td>
              <td align="center"> 
              <%
              filename = ServletUtilities.saveChartAsPNG(chart3,500,300,null,request.getSession());
      		  graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;
      		  request.getSession().setAttribute("graphURL", graphURL);
      		  request.getSession().setAttribute("filename", filename);
               
              %>
               <img src="<%=graphURL%>" style="width:99%"></img>
              </td> 
          </tr>
          <tr>
              <td align="center"> 
              <%
              filename = ServletUtilities.saveChartAsPNG(chart2,500,300,null,request.getSession());
      		  graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;
      		  request.getSession().setAttribute("graphURL", graphURL);
      		  request.getSession().setAttribute("filename", filename);
               
              %>
              <img src="<%=graphURL%>" style="width:99%"></img>
              </td>
              <td align="center"> 
               <%
              filename = ServletUtilities.saveChartAsPNG(chart4,500,300,null,request.getSession());
      		  graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;
      		  request.getSession().setAttribute("graphURL", graphURL);
      		  request.getSession().setAttribute("filename", filename);
               
              %>
              <img src="<%=graphURL%>" style="width:99%"></img>
              </td>
              
          </tr>
    </table>
</body>
</html>
